﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JTicket.UI
{
    public partial class S_ReturnTicket : System.Web.UI.Page
    {
        private readonly BLL.D_OperInfo bllOper = new BLL.D_OperInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Bind();
        }
        protected void dg1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemIndex == -1) return;
            e.Item.Attributes.Add("bgcolor", "#EFFFDA");
            e.Item.Attributes.Add("style", "cursor:hand");
            e.Item.Attributes.Add("onMouseOver=this.style.backgroundColor", "#DBE3FA");
            e.Item.Attributes.Add("onMouseOut=this.style.backgroundColor", "#F6F6F6");

        }
        void Bind()
        {
            this.txtBeginTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            this.txtEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            List<Model.D_TitleInfo> tileList = BLL.D_TitleInfo.
               GestListAll(bllOper.Oper().ThCode,
               DateTime.Parse(btime), DateTime.Parse(etime));
            this.DropDownList1.DataSource = tileList;
            this.DropDownList1.DataTextField = "Stitlename";
            this.DropDownList1.DataValueField = "StitleCode";
            this.DropDownList1.DataBind();

            string opercode = bllOper.Oper().OperCode;
            List<Model.L_ReturnProc> list = DAL.H_TicketBal.ReutnLog(opercode);
            this.dg2.DataSource = list;
            this.dg2.DataBind();
        }
        protected void txtBeginTime_TextChanged(object sender, EventArgs e)
        {
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            List<Model.D_TitleInfo> tileList = BLL.D_TitleInfo.
                 GestListAll(bllOper.Oper().ThCode,
                 DateTime.Parse(btime), DateTime.Parse(etime));
            this.DropDownList1.DataSource = tileList;
            this.DropDownList1.DataTextField = "Stitlename";
            this.DropDownList1.DataValueField = "StitleCode";
            this.DropDownList1.DataBind();
        }
        protected void txtEndTime_TextChanged(object sender, EventArgs e)
        {
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            List<Model.D_TitleInfo> tileList = BLL.D_TitleInfo.
               GestListAll(bllOper.Oper().ThCode,
               DateTime.Parse(btime), DateTime.Parse(etime));
            this.DropDownList1.DataSource = tileList;
            this.DropDownList1.DataTextField = "Stitlename";
            this.DropDownList1.DataValueField = "StitleCode";
            this.DropDownList1.DataBind();
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (dg1.Items.Count > 0)
            {    string BarCode = dg1.Items[0].Cells[0].Text;
                string TitleCode = dg1.Items[0].Cells[1].Text;
                if (!DAL.H_Return.Exist(BarCode, TitleCode))
                {
                    string Area = dg1.Items[0].Cells[4].Text;
                    string Row = dg1.Items[0].Cells[6].Text;
                    string Cow = dg1.Items[0].Cells[7].Text;
                    string Note = dg1.Items[0].Cells[5].Text;
                    string sixid = dg1.Items[0].Cells[8].Text;
                    string TicketName = dg1.Items[0].Cells[9].Text;
                    string OperCode = bllOper.Oper().OperCode;
                    string Model = "退票申请";
                    bool b = false;
                    b = DAL.H_TicketBal.ReturnTicket
                           (BarCode, TitleCode, Area, Row, Cow, Note, TicketName, OperCode, Model);
                    if (b)
                    {
                        Common.JsMsg.MsgBoxRedrect("退票申请操作成功!", "S_Return.aspx", this.Page);
                        Bind();
                    }
                    else
                        Common.JsMsg.Alert("退票操作失败，请重新操作！");
                }
                else
                    Common.JsMsg.Alert("此票已提交退票申请！");
            }
            else
                Common.JsMsg.Alert("请先查询到要退的门票！");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Items.Count > 0)
            {
                List<Model.H_TicketBal> list = DAL.H_TicketBal.GetSeachr(DropDownList1.SelectedItem.Value, this.t5.Text);
                this.dg1.DataSource = list;
                this.dg1.DataBind();
            }
            else
            {
                Common.JsMsg.Alert("请选择演出！"); 
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {if (DropDownList1.Items.Count > 0)
            {
            List<Model.H_TicketBal> list = DAL.H_TicketBal.GetSeachrFlag(DropDownList1.SelectedItem.Value, this.t6.Text);
            this.dg1.DataSource = list;
            this.dg1.DataBind();
            }
        else
        {
            Common.JsMsg.Alert("请选择演出！");
        }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Items.Count > 0)
            {
            List<Model.H_TicketBal> list = DAL.H_TicketBal.GetSeachr(DropDownList1.SelectedItem.Value, this.t2.Text, this.t3.Text, this.t4.Text);
            this.dg1.DataSource = list;
            this.dg1.DataBind(); }
            else
            {
                Common.JsMsg.Alert("请选择演出！"); 
            }
        }
    }
}